package logic

import (
	"context"
	"day15/houserpc/house"

	"day15/api/internal/svc"
	"day15/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HouseListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHouseListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HouseListLogic {
	return &HouseListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HouseListLogic) HouseList(req *types.HouseListRequest) (resp *types.ApiResponse, err error) {
	// todo: add your logic here and delete this line
	response, err := l.svcCtx.HouseSrv.HouseList(l.ctx, &house.HouseListReq{
		Page:     int64(req.Page),
		PageSize: int64(req.PageSize),
	})
	if err != nil {
		return &types.ApiResponse{
			Code: 0,
			Msg:  "查询失败",
			Data: nil,
		}, nil
	}
	return &types.ApiResponse{
		Code: 200,
		Msg:  "查询成功",
		Data: response,
	}, nil
}
